<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>MapVGL</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  <style>
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }
    #map_container {
      width: 100%;
      height: 100%;
      margin: 0;
    }
  </style>
  <script src="//api.map.baidu.com/api?v=2.0&ak=baiduKey"></script>
  <script src="//mapv.baidu.com/build/mapv.min.js"></script>
  <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.119/dist/mapvgl.min.js"></script>
</head>
<body>
<div id="map_container"></div>
<script>
  /* global BMap */

  /* global mapv */

  /* global mapvgl */

  /* global initMap */

  // 百度地图API功能
  var map = new BMap.Map('map_container', {
    enableMapClick: false
  }); // 创建Map实例

  /*
  map.setMapStyle({
      style: 'midnight'
  });
  */

  map.centerAndZoom(new BMap.Point(106.563777, 29.578285), 13); // 初始化地图,设置中心点坐标和地图级别
  map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放

  var view = new mapvgl.View({
    mapType: 'bmap',
    map: map
  });

  fetch('../../data/car.csv').then(function (rs) {
    return rs.text();
  }).then(function (csvstr) {
    var dataSet = mapv.csv.getDataSet(csvstr);
    var data = dataSet.get();
    dataSet.transferCoordinate(data, function (coord) {
      var projection = map.getMapType().getProjection();
      var point = projection.lngLatToPoint(new BMap.Point(coord[0], coord[1]));
      return [point.x, point.y];
    }, 'coordinates', 'coordinates');

    var newData = [];
    for (var i = 0; i < data.length; i++) {
      var item = data[i];
      var coordinates = item.geometry.coordinates;
      for (var j = 0; j < coordinates.length; j++) {
        newData.push({
          geometry: {
            type: 'POINT',
            coordinates: coordinates[j]
          }
        });
      }
    }

    var pointLayer = new mapvgl.PointLayer({
      blend: 'lighter',
      mapType: 'bmap',
      color: 'rgba(55, 55, 250, 0.8)',
      size: 2
    });
    view.addLayer(pointLayer);
    pointLayer.setData(newData);
  });
</script>
</body>
</html>
